#include "user_function.h"

big_int sqr(big_int x)
{
   return x * x;
}

big_int fact(big_int x)
{
   if (x < 0)
      return 0;
   big_int result = 1;
   for (big_int i = 2; i <= x; i += 1)
      result *= i;
   return result;
}

big_int digits(big_int a)
{
   a = abs(a);
   if (a < 10)
      return 1;
   big_int len = 0;
   big_int x = 1;
   while (x <= a)
   {
      len += 1;
      x *= 10;
   }
   return len;
}

struct user_functions
{
   user_functions()
   {
      get_function()["sqr"] = user_function_i(sqr);
      get_function()["fact"] = user_function_i(fact);
      get_function()["digits"] = user_function_i(digits);
   }
};

user_functions func;

std::map<std::string, user_function_i>& get_function()
{
   static std::map<std::string, user_function_i> result;
   return result;
}

